Skip to main content
Version: 0.5.1

getMultiRuntimeCb

This method executes a async function several times and calculates its execution time several times and puts it in an array and makes it available to you as a callback.

Params

getMultiRuntimeCb(inputFunction,Cb,options = { ignoreFirstTime: false, runtimeCount: 5 ,moreDetails : false}) ;
  • inputFunction → The async function we want to calculate its execution times
  • Cb → A function that will be called as a callback and the output will be passed to this function
take care

When you use this method, be sure to define the callback function

  • ignoreFirstTime → In this method, you can set this key to true and the first execution is not considered.
javascript tips

The execution time of a function in the first time is completely different from the subsequent times, because JavaScript performs optimizations on the execution of that function.

  • runtimeCount → The number of times you want this function to be executed and its time taken
  • moreDetails → Gives more information than execution times

Returns

cb(err,runtimes){
//codes
}
  • err → In case of any problem that causes this method to not be able to calculate runtimes, it will return the error in this parameter.
  • runtimes → Runtimes object is placed in this parameter

Usage

const inpFuncSync1 = async () => {
return await new Promise((resolve, reject) => {
setTimeout(() => {
resolve(true);
}, 2000);
});
};

getMultiRuntimeCb(inpFuncSync1,(err,result)=>{
console.log(result);/*{
runtimeCount: 5,
runtimes: [
2003.727125,
2003.1831670000001,
2003.1965,
2003.2178330000002,
2003.48375
]
}*/
})

getMultiRuntimeCb(inpFuncSync1,(err,result)=>{
console.log(result);/*{
runtimeCount: 13,
fastestRuntimes: 501.3837080000003,
slowestRuntimes: 501.61283300000014,
runtimes: [
501.3837080000003,
501.39508300000034,
501.398584,
501.401167,
501.39662499999986,
501.54574999999977,
501.5542910000004,
501.5580420000001,
501.5612920000003,
501.564167,
501.56733299999996,
501.5698339999999,
501.61283300000014
]
}*/
},{moreDetails: true, ignoreFirstTime: true ,runtimeCount : 13})